const loaderDiv = document.getElementById('loader-div'); let callRealityCheckInterval = null; class RealityCheck { constructor() { this.info = null; this.realityCheckPopup = null; this.realityCheckRefreshTime = 60000; } draw() { if(this.realityCheckPopup) return; this.realityCheckPopup = document.createElement('div'); this.realityCheckPopup.setAttribute('id', 'reality-check-popup'); loaderDiv.parentNode.insertBefore(this.realityCheckPopup, loaderDiv.nextSibling); this.setPopupHtml(); this.setHandlerElements(); scaleRealityCheckPopupMobile(); clearInterval(callRealityCheckInterval); } setPopupHtml() { globalParamsPromotion['HourPlayTime'] = this.info.HourPlayTime; globalParamsPromotion['MinutePlayTime'] = this.info.MinutePlayTime; this.realityCheckPopup.innerHTML = `

${GetCaption('reality.check.popup.title.reality.check')}

${GetCaption('reality.check.popup.message')}
${GetCaption('reality.check.popup.button.continue')}
${GetCaption('reality.check.popup.button.exit.from.game')}
${GetCaption('reality.check.popup.button.view.game.history')}
` } // You've been playing ${this.info.HourPlayTime} hours and ${this.info.MinutePlayTime} minutes. Your player history can be found in the "My account section of the website". setHandlerElements() { document.querySelector('.reality-check-button-continue').addEventListener('click', function() { realityCheck.continueGame(); }); document.querySelector('.reality-check-button-exit').addEventListener('click', function() { realityCheck.exitFromGame(); }); document.querySelector('.reality-check-button-history').addEventListener('click', function() { realityCheck.openGameHistory(); }); } continueGame() { this.resetPopup(); } exitFromGame() { document.querySelector('#game-frame').contentWindow.postMessage({ key: 'reality.check.popup.exit.from.game' }, "*"); this.resetPopup(); } openGameHistory() { document.querySelector('#game-frame').contentWindow.postMessage({ key: 'reality.check.popup.open.game.history' }, "*"); this.resetPopup(); } callCheckRealityMethod(realityCheckRefreshTime = this.realityCheckRefreshTime) { callRealityCheckInterval = setInterval(function() { ajaxReq = $.get(`${randomPointsGetPromotionUrl()}realityapi/RealityCheckApi/GetRealityCheck/${clientId}`, function (data) { if(realityCheck.realityCheckPopup) return; if(data) { realityCheck.info = data; document.querySelector('#game-frame').contentWindow.postMessage({ key: 'reality.check.popup.is.ready' }, "*"); } }).fail(function (jqXHR, textStatus, errorThrown) { }); }, realityCheckRefreshTime) } resetPopup() { this.realityCheckPopup.remove(); this.realityCheckPopup = null; document.querySelector('#game-frame').contentWindow.postMessage({ key: 'reset.reality.check.popup' }, "*"); this.callCheckRealityMethod(this.realityCheckRefreshTime); } checkRealityMethod() { ajaxReq = $.get(`${randomPointsGetPromotionUrl()}api/RealityCheckApi/IsActiveRealityCheck`, function (data) { if(data && data.RealityCheckIsActive) { realityCheck.realityCheckRefreshTime = data.RealityCheckRefreshTime; realityCheck.callCheckRealityMethod(data.RealityCheckRefreshTime); } }).fail(function (jqXHR, textStatus, errorThrown) { console.log(errorThrown); }); } } const realityCheck = new RealityCheck(); realityCheck.checkRealityMethod(); window.addEventListener("message", function(event) { if(event.data && event.data.key === 'draw.reality.check.popup') { realityCheck.draw(); } }, false); function randomPointsGetPromotionUrl(){ let url = window.location.href; url = url.split(".aspx?"); url = url[0]; let urlArray = url.split("/"); let promotionsUrl = urlArray[0] + "//"; for (let i = 1; i < urlArray.length - 1; i++) { if (urlArray[i] !== "") promotionsUrl += urlArray[i] + "/"; } return promotionsUrl; }; function scaleRealityCheckPopupMobile() { var width = $(window).width(); var height = $(window).height(); var o_width = 2170; var o_height = 1130; if (bowser.mobile) { o_width = 1280; o_height = 760; if (height > width) { o_width = 760; o_height = 1280; } } var w_scale = 0; var h_scale = 0; w_scale = width / o_width; h_scale = height / o_height; m_scale = Math.min(w_scale, h_scale); help_scale = m_scale; if (help_scale > 1) help_scale = 1; if (bowser.mobile) $(".reality-check-content").css({transform:"scale(" +( ( help_scale) ) + "," +( ( help_scale) ) + ")",}); }